home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
clean
/
sun3.lha
/
Sun3
/
seqdemos
/
reverse.icl
< prev
next >
Wrap
Text File
|
1992-08-07
|
816b
|
46 lines
MODULE reverse;
<<
Reversing a list.
A list containing n elements will be reversed n times.
>>
IMPORT deltaI;
MACRO
NrOfTimes -> 1000;
RULE
== Miscellaneous functions.
:: Last [INT] -> INT;
Last [x] -> x;
Last [x|r] -> Last r;
:: FromTo INT INT -> [INT];
FromTo a b -> [a] , IF = a b
-> [a | FromTo (++ a) b];
== Reversing a list of n integers n times.
:: Reverse INT -> INT;
Reverse n -> Last (Rev_n n (FromTo 1 n));
:: Rev_n INT [INT] -> [INT];
Rev_n 1 list -> Rev list [];
Rev_n n list -> Rev_n (-- n) (Rev list []);
:: Rev [INT] [INT] -> [INT];
Rev [x|r] list -> Rev r [x | list];
Rev [] list -> list;
== The Start rule.
:: Start -> INT;
Start -> Reverse NrOfTimes;